angular.module('moti.directive.modal', [])
    .provider('$modal', function(){

        var defaults = {
            backdrop : "static",
            keyboard : false,
            show : false,
            id : "tip-modal",
            text : "",
            delay : 1000
        };

        this.$get = function(){
            function ModalFactory(config){
                angular.extend(defaults, config);
                var $modal = {},
                    $modal_dom = $("#" + defaults.id);

                $modal_dom.modal(defaults);
                $modal.show = function(){
                    $modal_dom.find(".modal-body").html(defaults.text).end().modal("show");
                    return $modal;
                };
                $modal.hide = function(){
                    $modal_dom.modal("hide");
                    return $modal;
                };
                $modal.autoHide = function(){
                    $modal_dom.on("shown.bs.modal", function(){
                        setTimeout(function(){
                            $modal_dom.modal("hide");
                        }, defaults.delay);
                    });
                    return $modal;
                };

                return $modal;
            }
            return ModalFactory;
        }
    })
    .directive('modal', function(){
        return {
            restrict: 'AE',
            replace: true,
            scope: {},
            link: function(scope, elem){

            }
        };
    });